<?php
	session_start();
	
	require_once('config.php');
	
	if($_SESSION['logged'] && $_SESSION['username'] == USERNAME && $_SESSION['password'] == PASSWORD)
	{
		if(isset($_POST['day']))
		{
			$day = $_POST['day'];
			
			if(is_numeric($day))
			{
				$connect = new DbConnector();
				
				$next_day = $day + (24*3600);
				
				$delete = $connect->query("DELETE FROM ".$TABLES['detection']." WHERE unix_time >= ".$day." && unix_time <= ".$next_day."");
				
				if($delete)
				{
					echo 'Successfully deleted history!';
				}
			}
			else
			{
				echo 'Invalid data!';
			}
		}
	}
?>